<template>
<div>

<el-upload
  class="avatar-uploader"
  :action="action"
  ref="upload"
  :headers="headers"
  :show-file-list="false"
  :on-change="handlePictureCardPreview"
  :auto-upload="false">
  <img v-if="imageUrl" :src="imageUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
  <button @click="submitUpload">123</button>
</div>
</template>

<script>
import Api from "../../api/api";
  export default {
    data() {
      return {
        imageUrl: '',
        action:null,
        headers: {},
        file:null,
      };
    },
    created(){
    this.action = Api.uploads;
    // this.headers.Authorization = this.$store.state.token
    this.headers.Authorization = window.localStorage.token
  },
    methods: {
      handlePictureCardPreview(file) {
          this.file = file
         this.imageUrl = URL.createObjectURL(file.raw);
         this.$emit('getFile',file)
      },
      submitUpload() {
        this.$refs.upload.submit(this.file);
      },
    },
    
  }
</script>
<style lang="less" scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    i{
    display: flex;
    justify-content: center;
    align-items: center;
    }
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
